﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Daemon.Common.Auth
{
	public class LoginAuthorizationHandler : AuthorizationHandler<LoginRequirement>
	{
		private readonly ILogger<RoleAuthorizationHandler> _logger;

		private readonly IHttpContextAccessor _httpContextAccessor;

		public IAuthenticationSchemeProvider _schemes { get; set; }

		public LoginAuthorizationHandler(ILogger<RoleAuthorizationHandler> logger, IHttpContextAccessor httpContextAccessor, IAuthenticationSchemeProvider schemes)
		{
			_logger = logger;
			this._httpContextAccessor = httpContextAccessor;
			_schemes = schemes;
		}

		protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, LoginRequirement requirement)
		{
			var hasAuthorization = _httpContextAccessor.HttpContext.Request.Headers["Authorization"].Any();
			if (!hasAuthorization)
			{
				var token = _httpContextAccessor.HttpContext.Request.Headers["Token"];
				if (!string.IsNullOrEmpty(token))
				{
				}
				else
				{

				}
			}

			return Task.CompletedTask;
		}
	}
}
